package dart

class PlayerGameTests extends DartTestCase {

	void testAddingNewRound() {
		Game game = new Game(countDown: true, startingScore: 100, forceAllThrows: true,
				endingScore: 0, bounceBack: null, scoreLimit: null);
		PlayerGame playerGame = addPlayerGame(game);
		Classification cls = new Classification(scoreMultiplier: 1, penaltyMultiplier: 1)

		List attempts = []
		(0..2).each{
			attempts << new Attempt(classification: cls, type: Attempt.SUCCESS,
					value: 10, multiplier: 2)
		}

		playerGame.newRound(attempts);

		assertEquals(40, playerGame.currentScore());
		assertEquals(3, playerGame.rounds[0].attempts.size() );
	}

	void testNewRoundWithBust() {
		Game game = new Game(countDown: true, startingScore: 30, forceAllThrows: false,
				endingScore: 0, bounceBack: null, scoreLimit: null);
		PlayerGame playerGame = addPlayerGame(game);
		Classification cls = new Classification(scoreMultiplier: 1, penaltyMultiplier: 1)

		List attempts = []
		(0..2).each{
			attempts << new Attempt(classification: cls, type: Attempt.SUCCESS,
					value: 10, multiplier: 2)
		}

		playerGame.newRound(attempts);

		assertEquals(10, playerGame.currentScore());
		assertEquals(2, playerGame.rounds[0].attempts.size() );
	}

	void testNewRoundWithEarlyWin() {
		Game game = new Game(countDown: true, startingScore: 40, forceAllThrows: false,
				endingScore: 0, bounceBack: null, scoreLimit: null);
		PlayerGame playerGame = addPlayerGame(game);
		Classification cls = new Classification(scoreMultiplier: 1, penaltyMultiplier: 1)

		List attempts = []
		(0..2).each{
			attempts << new Attempt(classification: cls, type: Attempt.SUCCESS,
					value: 10, multiplier: 2)
		}

		playerGame.newRound(attempts);

		assertEquals(0, playerGame.currentScore());
		assertEquals(2, playerGame.rounds[0].attempts.size() );
	}

	void testNewRoundWithFakeOutWin() {
		Game game = new Game(countDown: true, startingScore: 40, forceAllThrows: true,
				endingScore: 0, bounceBack: 0, scoreLimit: null);
		PlayerGame playerGame = addPlayerGame(game);
		Classification cls = new Classification(scoreMultiplier: 1, penaltyMultiplier: 1)

		List attempts = []
		(0..2).each{
			attempts << new Attempt(classification: cls, type: Attempt.SUCCESS,
					value: 10, multiplier: 2)
		}

		playerGame.newRound(attempts);

		assertEquals(20, playerGame.currentScore());
		assertEquals(3, playerGame.rounds[0].attempts.size() );
	}

	void testNewRoundWithEndingWin() {
		Game game = new Game(countDown: true, startingScore: 60, forceAllThrows: true,
				endingScore: 0, bounceBack: 0, scoreLimit: null);
		PlayerGame playerGame = addPlayerGame(game);
		Classification cls = new Classification(scoreMultiplier: 1, penaltyMultiplier: 1)

		List attempts = []
		(0..2).each{
			attempts << new Attempt(classification: cls, type: Attempt.SUCCESS,
					value: 10, multiplier: 2)
		}

		playerGame.newRound(attempts);

		assertEquals(0, playerGame.currentScore());
		assertEquals(3, playerGame.rounds[0].attempts.size() );
	}

}